<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        // ES5
        // function 
        function Cat(name,color){
            this.name = name;
            this.color=  color;
        }
        // 原型对象接受一些公共的属性和方法 
        Cat.prototype.type = "Cat";
        Cat.prototype.call = function(){
            console.log('喵喵~~')
        }
        Cat.prototype.skill = function(){
            console.log('我会抓老鼠')
        }
        Cat.prototype.say = function(){
            console.log(this.name,this.color);
        }
        // 静态属性
        Cat.hobby = ["睡觉","吃鱼"];

        // ES6   (箭头函数  字符串模板  let const promise async+await 扩展运算符  解构  class )  
        // ES6  会通过插件 转成 ES5 代码 

        // class 声明一个构造函数  (构造器 +  原型对象 + 静态对象)

        class Person{
            // 构造器  没有参数可以省略 
            constructor(name,age){
                this.name = name;
                this.age = age;
            }

            // 原型对象 
            say(){
                console.log("say wh2107")
            }

            eat(){
                console.log("eat apple")
            }

        }
        // Person.prototype.say = function(){
        //     console.log("say hello")
        // }
        // static 
        Person.hobby = ["赚钱","吃饭"]  

        var p1 = new Person("zuozuomu",28);
        console.log(p1);
        console.log(p1.__proto__.constructor === Person)
        console.log(p1.name)
        console.log(p1.age)
        console.log(Person.hobby)
        p1.say()


        class Student{

        }

        class GetEle{
            constructor(selector){
                this.eles =  document.querySelectorAll(selector)
            }

            // prototype 
            html(text){
                if(arguments.length>= 1){   // 有参数 
                    for(var i=0;i<this.eles.length;i++){
                        var ele = this.eles[i];
                        ele.innerHTML = text;
                    }
                    return this;
                }else{
                    // 没有传参数  
                    return this.eles[0].innerHTML;
                }
            }
        }
    </script>
</body>
</html>